package com.aqie.mp.service.impl;


import com.aqie.mp.entity.User;
import com.aqie.mp.mapper.UserMapper;
import com.aqie.mp.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author aqie
 * @date 2020-09-12 8:48
 * @function
 * 常用查询 http://www.vmfor.com/p/101358283368.html
 */
@Service
@AllArgsConstructor
@Slf4j
public class UserServiceImpl implements IUserService {
    private UserMapper userMapper;

    @Override
    public int add(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int update(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public User get(long id) {
        return userMapper.selectById(id);
    }

    @Override
    public List<User> conditionList() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.like("username","aqie").between("age",20,30).isNotNull("email");
        List<User> userList = userMapper.selectList(queryWrapper);
        return userList;
    }

    @Override
    public List<User> list() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public int delete(long id) {
        int i = userMapper.deleteById(id);
        log.info("{}", i);
        return i;

    }
}
